package friendly_link

import (
	friendly_link_db "hft/Database/admin/friendly_link"
	"hft/Http/Models/request"
	"hft/Http/Services/friendly_link"
	"hft/Http/Services/friendly_link/friendly_link_model"
	utils "hft/Http/Utils"

	"github.com/gin-gonic/gin"
)

type FriendlyLink struct{}

// 获取列表
func (*FriendlyLink) List(c *gin.Context) {
	var paginate utils.Page
	c.ShouldBind(&paginate)
	list := friendly_link.FriendlyLinkService.GetFriendlyLink(&paginate)
	utils.OkWithData(list, c)
}

// 创建
func (*FriendlyLink) Create(c *gin.Context) {
	var data *friendly_link_db.GloFriendlyLink
	c.ShouldBindJSON(&data)
	if err := friendly_link.FriendlyLinkService.CreateFriendlyLink(data); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

// 编辑
func (*FriendlyLink) Edit(c *gin.Context) {
	var data *friendly_link_db.GloFriendlyLink
	c.ShouldBindJSON(&data)
	if err := friendly_link.FriendlyLinkService.Edit(data); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

// 删除
func (*FriendlyLink) Delete(c *gin.Context) {
	var ids *request.IDS
	c.ShouldBindJSON(&ids)
	if err := friendly_link.FriendlyLinkService.Delete(ids.IDS); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

// 获取友情列表
func (*FriendlyLink) CityList(c *gin.Context) {
	var paginate friendly_link_model.FriendlyCityLinkSearch
	c.ShouldBind(&paginate)
	list := friendly_link.FriendlyLinkService.GetCityLink(&paginate)
	utils.OkWithData(list, c)
}

// 创建
func (*FriendlyLink) CreateCityLink(c *gin.Context) {
	var data *friendly_link_db.CityFriendLyLink
	c.ShouldBindJSON(&data)
	if err := friendly_link.FriendlyLinkService.CreateCityFriendlyLink(data); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

// 编辑
func (*FriendlyLink) EditCityLink(c *gin.Context) {
	var data *friendly_link_db.CityFriendLyLink
	c.ShouldBindJSON(&data)
	if err := friendly_link.FriendlyLinkService.EditCityFriendlyLink(data); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

// 删除
func (*FriendlyLink) DeleteCityLink(c *gin.Context) {
	var ids *request.IDS
	c.ShouldBindJSON(&ids)
	if err := friendly_link.FriendlyLinkService.DeleteCityFriendlyLink(ids.IDS); err != nil {
		utils.FailWithMessage(err.Error(), c)
	} else {
		utils.Ok(c)
	}
}

// 获取城市
func (*FriendlyLink) GetCityList(c *gin.Context) {
	list := friendly_link.FriendlyLinkService.GetCityList()
	utils.OkWithData(list, c)
}

var FriendlyLinkController = new(FriendlyLink)
